<template>
  <div>
    <table-expand
      ref="table"
      :columns="columns"
      :data="data"
      :loading="loading"
      :config="config"
      :pageSizeOpts="pageSizeOpts"
      :pageNavigation="pageNavigation"
      :queryFormItem="queryFormItem"
      :collapseFormItem="collapseFormItem"
      :action="action"
      @loadPage="loadPage"
      @handleSearch="handleSearch"
      @handleReset="handleReset"
    ></table-expand>
  </div>
</template>

<script>
import { typeClassName } from "@/pages/config/classNameMap";
import tableExpand from "@/pages/components/tableExpand.vue";
import columnsMixin from "./config";
export default {
  components: { tableExpand },
  name: "workshop",
  mixins: [columnsMixin],
  data() {
    return {
      data:[],
      collectionObject: null, // 所有实例
      className: typeClassName["locationRecord"].className,
      type: typeClassName["locationRecord"].type,
      modelType: typeClassName["locationRecord"].modelType,
      loading: false,
      statusOptions:[{value:'0',label:'未占用'},{value:'1',label:'已占用'}],
      action: {
        edit: false,
        delete: false,
        detail: false,
      },
      config: {
        search: true,
        addButton: false,
        batchDeleteButton: false,
        tableSizeIcon: true,
        fullscreenIcon: true,
        refreshIcon: false,
        columnSettingIcon: true,
        action: false,
        additionalAction: false,
      },
      pageSizeOpts: [10, 30, 50, 100],
      pageNavigation: { total: 0, pageSize: 10, pageNumber: 1 },
    };
  },
  mounted() {
    this.collectionObject = this.$modelObject.create(
      `${this.modelType}Collection`
    );
    this.loadPage(this.pageNavigation, null);
  },
  methods: {
    loadPage(pageNavigation, filter) {
      //删除查询项中属性值为空的查询条件
      this.tools.deleteInvalid(filter);
      this.loading = true;
      this.$api.Custom.storeQuery([{
          pageNumber:pageNavigation.pageNumber,
          pageSize:pageNavigation.pageSize,
          ...filter
      }]).then(res => {
        this.data = res.records;
        this.pageNavigation.total = res.recordCount;
        this.loading = false;
      }).catch(err=>{
        console.log(err);
        this.loading = false
      })
    },
    handleSearch (filter) {
        this.pageNavigation.pageNumber = 1;
        this.loadPage(this.pageNavigation, filter);
    },
    handleReset () {
        this.pageNavigation.pageNumber = 1;
        this.loadPage(this.pageNavigation, null);
    },
    getCellBg (status) {
        switch (status) {
          case '0':
            return {color:'default',text:'未占用'};
          case '1':
            return {color:'success',text:'已占用'};
          default:
            return {color:'default',text:'未占用'};
        }
    },
  },
};
</script>
<style scoped lang="scss"></style>
